/**
*┌──────────────────────────────────────────────────────────────┐
*│　描    述：User_message                                                    
*│　作    者：NetCoreCMS                                            
*│　版    本：1.0    模板代码自动生成                                                
*│　创建时间：2019-12-25 10:52:46                             
*└──────────────────────────────────────────────────────────────┘
*┌──────────────────────────────────────────────────────────────┐
*│　命名空间： NetCoreCMS.Services                                  
*│　类    名： User_messageService                                    
*└──────────────────────────────────────────────────────────────┘
*/
using NetCoreCMS.IRepository;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetCoreCMS.Services
{
    public class User_messageService: IUser_messageService
    {
        private readonly IUser_messageRepository _repository;

        public User_messageService(IUser_messageRepository repository)
        {
            _repository = repository;
        }

        public int Add(User_message model)
        {
            return (int)_repository.Insert(model);
        }

        public int Add(int type, string post_user_name, string accept_user_name, string title, string content)
        {
            Models.User_message model = new Models.User_message();
            model.type = type;
            model.post_user_name = post_user_name;
            model.accept_user_name = accept_user_name;
            model.title = title;
            model.content = content;
            return Add(model);
        }

        public bool Delete(int id)
        {
            return _repository.Delete(id) > 0;
        }

        public bool Delete(int id, string user_name)
        {
            return _repository.DeleteList("where id=@id and (post_user_name=@user_name or accept_user_name=@user_name)", new { id=id,user_name=user_name}) > 0;
        }

        public bool Exists(int id)
        {
            return GetModel(id) != null ? true : false;
        }

        public List<Models.User_message> GetList(int pageNumber, int rowsPerPage, string conditions, string orderby, object parameters = null)
        {
            return _repository.GetListPaged(pageNumber, rowsPerPage, conditions, orderby, parameters).ToList();
        }

        public User_message GetModel(int id)
        {
            return _repository.Get(id);
        }

        public int RecordCount(string conditions, object parameters = null)
        {
            return _repository.RecordCount(conditions, parameters);
        }

        public bool UpdateField(int id, string strValue)
        {
            return _repository.UpdateField(id, strValue);
        }
    }
}